package com.smart.nine.spel.summary.evaluationcontext;

import org.springframework.expression.EvaluationContext;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

/**
 * 测试类
 *
 * @author junrui.wang
 * @create 2019/3/19
 */
public class Test {
    public static void main(String[] args) {
        SimpleList simpleList = new SimpleList();
        simpleList.list.add(true);

        ExpressionParser expressionParser = new SpelExpressionParser();
        //创建求值上下文
        EvaluationContext evaluationContext = new StandardEvaluationContext(simpleList);
        //自动将false转换为boolean，如果值错误会报错(SpelEvaluationException)
        expressionParser.parseExpression("list[0]").setValue(evaluationContext, "false");
        //list[0]将被设置为false
        System.out.println(simpleList.list.get(0));
    }
}
